/**
 * 使用自定义标识符终止线程
 */
public class ThreadInterrupt{
    //1.声明一个自定义标识符
    private  volatile static boolean flag=false;
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread(()->{
            while(!flag){
                System.out.println("正在转账...");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("啊？差点误了大事！");
        });
        thread.start();
        Thread.sleep(3000);
        //终止线程
        System.out.println("有内鬼，终止交易");
        flag=true;
    }
}
